package com.woniuxy.util;

import com.woniuxy.controller.info.Result;
import com.woniuxy.util.exception.GlobalException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e ){
        e.printStackTrace();
        return Result.getInstance().setCode(500).setMsg("全局异常捕获错误"+e.getMessage());
    }
    @ExceptionHandler(GlobalException.class)
    public Result handleGlobalException(GlobalException e){
        e.printStackTrace();
        return Result.getInstance().setCode(500).setMsg(e.getMessage());

    }
    @ExceptionHandler(AccessDeniedException.class)
    public Result handleAccessDeniedException(AccessDeniedException e){
        e.printStackTrace();
        return Result.getInstance().setCode(500).setMsg(e.getMessage());
    }

}
